import asyncio
from lib.net.index import wlan,tcp
from utils import device

__service__ = "http_heartbeat"
__description__ = "codemao http heartbeat"

def init():
    # 检查当前网络状态和网络模式
    if not wlan.is_connected():
        print("wifi not connected")


async def run():
    while True:
        tcp.connect("creation-hardware.codemao.cn", 3000)
        did = device.get_id()
        buf = '{"op": "upload","topic":"Tiot_4v7H8WuO","name":"dataset","data": "esp32,esp32c3,' + did + ',4"}'
        tcp.write(buf)
        #tcp.disconnect()
        await asyncio.sleep(10)
